/* Lista imagens */
package servlets;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import beans.Imagem;
import beans.Video;
import dbclass.ImagemDAO;
import dbclass.ImagemJDBC;
import dbclass.VideoDAO;
import dbclass.VideoJDBC;

/**
 * Servlet implementation class Fotos
 */
public class Imagens extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Imagens() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(true);
		//Verifica login
		if(session.getValue("autor_login") == null) {
			response.sendRedirect("Home?msg_erro=Acesso Negado");  return;
		} 
		
		
		ImagemDAO fotoDAO = new ImagemJDBC(); 
		
		String action = (String)request.getParameter("action");
		session.setAttribute("action", action); 
		
		List<Imagem> imagens = null;  
		try {
			imagens = fotoDAO.findAll();   
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace(); 
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace(); 
		}
		session.setAttribute("imagens", imagens);  
	
		 
		String url="/Imagens.jsp";   
		ServletContext sc = getServletContext();
		RequestDispatcher rd = sc.getRequestDispatcher(url);
		rd.forward(request, response);   
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}

}
